package edu.friday.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @title: Swagger2Configuration
 */
@Configuration
@ConditionalOnExpression("${swagger.enable:true}")
public class Swagger2Configuration {

    /**
     * 生成API文档页面请求
     *
     * @return
     */
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("edu.friday.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建Api文档页面信息
     *
     * @return
     */
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API接口文档")
                .description("API接口文档")
//                .termsOfServiceUrl("http://baidu.com")
                .version("1.0")
                .build();
    }
}
